#导包
from django.http import HttpResponse
#导入类视图
from django.views import View
import json
# 导入又拍云
import upyun

#定义地址和端口
host = '127.0.0.1'
port = 6379

# #建立redis连接
# r = redis.Redis(host=host,port=port)


# 定义又拍云文件上传类
class YouPai(View):
    def post(self,request):
        img = request.FILES.get('file')
        print(img)

        up = upyun.UpYun('1907b','tt1216124438','ahrPZf37Jw6KXBtRxOoF1RrEwKmnapNg')
        print(up,'************')
        headers = { 'x-gmkerl-rotate': '180' }
        
        for chunk in img.chunks():
            res = up.put('../static/12.jpg', chunk, checksum=True, headers=headers)


        #返回结果
        return HttpResponse(json.dumps({'filename':img.name}),content_type='application/json')